local shiju = fk.CreateSkill{
    name = "wk_heg__shiju",
}

local H = require "packages.ol_hegemony.util"
local HG = require "packages.new_heg_diy_my.util"


Fk:loadTranslationTable{
  ["wk_heg__shiju"] = "势举",
  [":wk_heg__shiju"] = "当你受到伤害后，你可以令一名与你势力相同的角色选择一项：1.交给你一张牌，其“合纵”规则改为与你相同直至其回合结束；2.视为对伤害来源使用一张【杀】。",

  ["wk_heg__shiju_change"] = "修改“合纵”规则",
  ["wk_heg__shiju_slash"] = "视为使用【杀】",
  ["wk_heg__shiju_pro"] = "势举：你可以选择一名与你势力相同的角色，其修改“合纵”规则与你相同或视为使用【杀】",
  ["#wk_heg__shiju-give"] = "势举：请选择一张牌",

  ["$wk_heg__shiju1"] = "此危亡之时，当出此急谋。",
  ["$wk_heg__shiju2"] = "急筹布画，运策捭阖。",
}

shiju:addEffect(fk.Damaged,{
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(shiju.name) and player == target
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return H.compareKingdomWith(p, player) end)
    local tos = room:askToChoosePlayers(player, {
        targets = targets,
        min_num = 1,
        max_num = 1,
        prompt = "wk_heg__shiju_pro",
        skill_name = shiju.name,
        cancelable = true,
      })
    if #tos > 0 then
      local to = tos[1]
      local choices = {}
      if player ~= to and not to:isNude() and player:getMark("wk_heg__jilun_alliance") > 0 then
        table.insert(choices, "wk_heg__shiju_change")
      end
      if not to:prohibitUse(Fk:cloneCard("slash")) and to ~= data.from then
        table.insert(choices, "wk_heg__shiju_slash")
      end
      if #choices == 0 then return false end
      local choice = room:askToChoice(to, {
        choices = choices, 
        skill_name = self.name
      })
      if choice == "wk_heg__shiju_change" then
        local cards = room:askToCards(to, {
          min_num = 1,
          max_num = 1,
          include_equip = false,
          skill_name = shiju.name,
          prompt = "#wk_heg__shiju-give",
          cancelable = false,
        })
        room:obtainCard(player, cards, false, fk.ReasonGive)
        local mark_alliance = player:getMark("wk_heg__jilun_alliance")
        room:setPlayerMark(to, "wk_heg__jilun_alliance_change", mark_alliance)
        if mark_alliance == 1 then
          room:handleAddLoseSkills(to, "alliance1&", nil)
        elseif mark_alliance == 2 then
          room:handleAddLoseSkills(to, "alliance2&", nil)
        elseif mark_alliance == 3 then
          room:handleAddLoseSkills(to, "alliance3&", nil)
        end
        if player:getMark("wk_heg__jilun_alliance") > 0 or player:getMark("wk_heg__jilun_alliance_change") > 0 then 
          to:setSkillUseHistory("alliance&", 99, Player.HistoryPhase)
        end
      else
        room:useVirtualCard("slash", nil, to, data.from, shiju.name, true)
        -- local card
        -- local cards = {}
        -- local _pattern = ".|.|.|.|.|basic"
        -- if #room:getCardsFromPileByRule(_pattern, 1) == 0 then return false end
        -- while true do
        --   local id = room:getNCards(1)[1]
        --   room:moveCardTo(id, Card.Processing, nil, fk.ReasonJustMove, self.name)
        --   room:delay(300)
        --   local c = Fk:getCardById(id)
        --   if c:getTypeString() == "basic" or HG.HasMark(c, "@@alliance-public", MarkEnum.CardTempMarkSuffix) then
        --     card = c
        --     break
        --   else
        --     table.insert(cards, id)
        --   end
        -- end
        -- room:moveCardTo(card.id, Player.Hand, to, fk.ReasonPrey, self.name, nil, true, player.id)
        -- cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
        -- room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
      end
    end
  end,
})

return shiju